package com.HuangJiaQing.www.service.impl;

import com.HuangJiaQing.www.dao.BillMapper;
import com.HuangJiaQing.www.dao.CourierMapper;
import com.HuangJiaQing.www.model.Bill;
import com.HuangJiaQing.www.model.BillExample;
import com.HuangJiaQing.www.model.Courier;
import com.HuangJiaQing.www.model.CourierExample;
import com.HuangJiaQing.www.service.CourierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author HONOR
 * @date 2022/8/6 11:22
 */
@Service
public class CourierServiceImpl implements CourierService {
    @Autowired
    private CourierMapper courierMapper;
    @Autowired
    private HttpSession httpSession;
    @Autowired
    private BillMapper billMapper;

    public boolean registerCourier(Courier courier) {
        CourierExample courierExample = new CourierExample();
        courierExample.createCriteria().andCourierNameEqualTo(courier.getCourierName());
        List<Courier> couriers = courierMapper.selectByExample(courierExample);
        if (couriers.isEmpty()){
            courierMapper.insertSelective(courier);
            return true;
        }else {
            return false;
        }
    }

    public List<Bill> courierLogin() {
        Courier courier = (Courier) httpSession.getAttribute("courier");
        BillExample billExample = new BillExample();
        billExample.createCriteria().andCourierNameEqualTo(courier.getCourierName()).andIsCompleteEqualTo(0);
        List<Bill> bills = billMapper.selectByExampleWithGoods(billExample);
        return bills;
    }
}
